//
//  KXCover.swift
//  开心微博
//
//  Created by 郑开心 on 15/12/6.
//  Copyright © 2015年 郑开心. All rights reserved.
//

import UIKit
protocol KXCoverDelegate{
    func coverDidClickCover(cover: KXCover)
}

class KXCover: UIView {
    
    var delegate : KXCoverDelegate?
    
    var dimBackground : Bool!{
        get{
            return self.dimBackground
        }
        set(newValue){
            self.dimBackground = newValue
            if self.dimBackground! {
                self.backgroundColor = UIColor.blackColor()
                self.alpha = 0.5
            }else{
                self.alpha = 1
                self.backgroundColor = UIColor.clearColor()
                
            }
        }
    }
    
    class func show() -> KXCover{
        let screenB = UIScreen.mainScreen().bounds
        let cover = KXCover(frame: screenB)
        cover.backgroundColor = UIColor.clearColor()
        
        UIApplication.sharedApplication().keyWindow?.addSubview(cover)
    
        return cover
    }
    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        self.removeFromSuperview()
        
        delegate?.coverDidClickCover(self)
    }
}
